package common;

import com.google.gson.annotations.Expose;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by lxl on 2015/10/30.
 */
public class Result<T> implements Serializable{

    private  static  final  long serialVersionUID = 1L;

    @Expose
    private  boolean isSucces = true ;

    @Expose
    private Map<String , Object> param = new HashMap<String,Object>() ;

    @Expose
    private  String error ;

    private T returnValue ;

    public boolean isSucces() {
        return isSucces;
    }

    public void setSucces(boolean isSucces) {
        this.isSucces = isSucces;
    }

    public T getReturnValue() {
        return returnValue;
    }

    public void setReturnValue(T returnValue) {
        this.returnValue = returnValue;
    }


    public void setParam(Map<String, Object> param) {
        this.param = param;
    }

    public Map<String, Object> getParam() {
        return param;
    }

    public void addParam( String key , Object value){
        param.put(key,value) ;
    }

    public  Object searchParam( String key ){
        return  param.get(key) ;
    }

    public Object getParamValue( String key ){
        if( param == null ){
            return  null ;
        }
        return  param.get(key);
    }


    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
        if( error != null ){
            this.isSucces = false ;
        }
        else {
            this.isSucces = true ;
        }
    }

    @Override
    public String toString() {
        return "Result{" +
                "isSucces=" + isSucces +
                ", param=" + param +
                ", error='" + error + '\'' +
                ", returnValue=" + returnValue +
                '}';
    }
}
